package com.zhang.sdk.utils.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Build;

/**
 * Activity检测类
 *
 * 功能：Activity有关功能
 * @author zhang.x
 */
public class ActivityCheckUtil {

    /**
     * activity是否未释放
     *
     * @param context 上下文
     * @return true：有效  false：已经释放
     */
    @SuppressLint("ObsoleteSdkInt")
    public static boolean isActive(Context context) {
        if (context == null) {
            return false;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                return !activity.isDestroyed();
            } else {
                return !activity.isFinishing();
            }
        }
        return true;
    }
}
